#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
# File Name: cmd_show.sh
# Author: GID5564
# Description: 展示简化命令及描述
# Created Time: 14/09/24-15:06:15
#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
#! /usr/bin/env bash

function __command_show_init__(){
    export SHOW_CONFIG="${CONFIG_PATH}/.menu"
    export SYSTEM_CONFIG="${CONFIG_PATH}/.system"
    export MAIL_CONFIG="${CONFIG_PATH}/.sendmail"
    
    if [[ ! -s ${SHOW_CONFIG} ]];then
        [[ ! -d ${CONFIG_PATH} ]] && mkdir ${CONFIG_PATH}
        __write_config_show__
    fi
}
function __write_config_show__(){
    cat >>${SHOW_CONFIG} <<-'EOF'
[command]
#可以在此添加有效命令的简化形式，以便能直现展示，防止遗忘。
vmenu = *添加命令*
main = 功能主菜单

vvim = 配置~/.vimrc
vzsh = 配置~/.zshrc
vbsh = 配置~/.bashrc
motd = 配置启动问候语

av|ov|qv = 虚拟环境操作 

web = web服务,后加端口号

jn = Jupyter Notebook
topy = ipynb转py

push = git上传
gh = 代码提交到git
tldr = 命令详解，后加linux命令
sc = shell语法检查，后加*.sh

EOF
}


#定义别名，终端缩短命令
function __command_alias__(){
    
    alias main="menu_main"
    alias topy="jupyter nbconvert --to script *.ipynb"
    alias gitup="git push origin master --force"
    alias gh='UpdateRemoteGit "/home/aidlux/.aidtool" "aidlux"'
    
    alias qv="quit_virtualenv" #退出
    alias ov="open_env" #打开
    alias av="add_virtualenv" #创建
    
    alias sc="shellcheck "
    
    # ♦开启web服务
    alias web="python3 -m http.server --cgi "

    # ♦配置bash
    alias vbsh="vim ${FILE_BASH}"

    # ♦修改termux启动问候语
    alias motd="vim ${FILE_MOTD}"

    # ♦配置Vim
    alias vvim="vim ${FILE_VIM}"

    # ♦配置zsh 主题及设别称
    alias vzsh="vim ${FILE_ZSH}"
    
    # ♥配置.menu文件
    alias vmenu="vim ${SHOW_CONFIG}"

    # ♥配置.system文件
    alias vsys="vim ${SYSTEM_CONFIG}"
    
    # ♥配置.sendmail文件
    alias vmail="vim ${MAIL_CONFIG}"
    
    # ♥配置.config文件
    alias vconf="vim ${FILE_CONFIG}"
    
    # ♦更新源
    alias pu="sudo apt update"

    # ♦更新包
    alias pug="sudo apt -y upgrade"

    # ♦下载软件包apt
    alias pkg="sudo apt -y install "

    # ♦下载清华源pip3
    alias  pipi="pip3 install -i ${MODE_SOURCE} "

    # ♦安装deb包
    alias debi="sudo dpkg -i "

    # ♦打包当前目录下的所有文件为data.zip
    alias zp="zip -r data.zip * "

    # ♦输出已安装库到pip.txt
    alias txt="pip freeze >pip.txt"

    # ♦打开jupyter notebook
    alias jn="jupyter notebook --allow-root  --no-browser "
    ##jupyter notebook --ip=0.0.0.0 --port 8000 --no-browser --allow-root
}


function _show_command_menu_(){
    if [[ ! -s ${SHOW_CONFIG} ]];then
        return 1
    fi
    if [[ -z $1 ]];then
        return 1
    fi
    local SECTION=$1
    local KEYS=$(get_keys ${SHOW_CONFIG} ${1})
    if [[ -z $KEYS ]];then
        return 1
    fi
    KEYS=(`echo ${KEYS}|grep "[A-Za-z0-9_]" |awk -v RS='' '{gsub(" "," "); print}'`)
    spec_char '\n'
    msg "${BLUE}可以输入以下${RESET}${YELLOW}命令${RESET}${BLUE}，进入相应功能: ${RESET}"
    hr '-' 45
    #循环读取ini
    local cnt=1
    for key in ${KEYS[@]}
    do
        local value=$(read_ini ${SHOW_CONFIG} ${SECTION} ${key})
        local ser="${cnt}."
        prf "${ser}" "${value}" "${key}"
        let cnt++
        unset value
    done
    unset SECTION KEYS cnt ser
    hr '-' 45
    
    __command_alias__
}
















__command_show_init__